﻿using SmartRFIDSystem.dao;
using SmartRFIDSystem19.model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SmartRFIDSystem19.view
{
    public partial class FindPass : Form
    {
        private string cap="";
        public FindPass()
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            InitializeComponent();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void change_Click(object sender, EventArgs e)
        {
            if (txt_userName1.Text.Equals("") || txt_email1.Text.Equals("") || txt_captcha1.Text.Equals("") || new_pass.Text.Equals("") || confirm_pass.Text.Equals(""))
            {
                MessageBox.Show("内容为空，请填写完整");
            }
            else if
            (cap.Equals(""))
            {
                MessageBox.Show("请发送验证码");
            }
            else if (!new_pass.Text.Equals(confirm_pass.Text))
            {
                MessageBox.Show("两次密码不一致");
            }
            else if (!model.Captcha.CheckCode(cap, this.txt_captcha1.Text))
            {
                MessageBox.Show("验证码错误！");
            }
            else
            {
                UserDao user = new UserDao();
                if (user.ChangePassword(txt_userName1.Text, new_pass.Text, txt_email1.Text) == 1)
                {
                    this.Close();
                }
            }


        }

        private void FindPass_Load(object sender, EventArgs e)
        {

        }

        private void send_Click(object sender, EventArgs e)
        {
            //生成五位数的验证码
            cap = model.Captcha.GetRandomCode(5);
            //将五位数的验证码发送到填写的邮箱
            Mail.sendMail(txt_email1.Text, "智慧一卡通系统找回密码验证码", "本次验证码为：" + cap);
        }
    }
}
